package com.caojin.propertyInjector.struts2;

import org.apache.struts2.impl.StrutsActionProxyFactory;

import com.caojin.propertyInjector.UrlResolver;
import com.caojin.propertyInjector.annotation.AnnotationResolver;
import com.caojin.propertyInjector.annotation.SimpleAnnotationResolver;
import com.caojin.propertyInjector.util.PropertyInjectorUtil;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.inject.Inject;
/**
 * struts2 中将配置信息注入到类的成员变量上
 * @author caojin
 */
public class StrutsPropActionProxyFactory extends StrutsActionProxyFactory {
	//注解解析器
	@Inject(value = "annotationResolver", required = false)
	private AnnotationResolver annotationResolver;
    //url解析器
	@Inject(value = "urlResolver", required = false)
	private UrlResolver urlResolver;

	@Override
	public ActionProxy createActionProxy(ActionInvocation inv,
			String namespace, String actionName, String methodName,
			boolean executeResult, boolean cleanupContext) {
		ActionProxy proxy=super.createActionProxy(inv, namespace, actionName, methodName,
				executeResult, cleanupContext);
		if (annotationResolver == null) {
			annotationResolver = new SimpleAnnotationResolver();
		}
		if (urlResolver != null) {
			annotationResolver.setUrlResolver(urlResolver);
		}
		Object action = inv.getAction();
		PropertyInjectorUtil.executePropInject(action, annotationResolver);
		return proxy;
	}
}
